﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Diagnostics;
using System.Drawing;
using System.Linq;
using System.Runtime.InteropServices;
using System.Text;
using System.Threading;
using System.Windows.Forms;

namespace WindowsFormsApplication
{
    public partial class Form1 : Form
    {
        private VolumeControl volumeControl = VolumeControl.Instance;
        SynchronizationContext m_SyncContext = null;
        public Form1()
        {
            InitializeComponent();
            m_SyncContext = SynchronizationContext.Current;
            lblCur.Text = volumeControl.MasterVolume.ToString("####");
            cbMute.Checked = volumeControl.IsMute;
            volumeControl.OnAudioNotification += Audio_Notice;
        }

        private void Audio_Notice(object sender, AudioNotificationEventArgs e)
        {
            m_SyncContext.Post(Audio_Notice, e);
         //   lblCur.Text = e.MasterVolume.ToString("####");
          //  cbMute.Checked = e.Muted;
        }

        private void Audio_Notice(object sender)
        {
            AudioNotificationEventArgs e = (AudioNotificationEventArgs)sender;
            lblCur.Text = e.MasterVolume.ToString("####");
            cbMute.Checked = e.Muted;
        }

        private void button1_Click(object sender, EventArgs e)
        {
            var i = ++volumeControl.MasterVolume;
            volumeControl.MasterVolume = i;
        }

        private void button2_Click(object sender, EventArgs e)
        {
            var i = --volumeControl.MasterVolume;
            volumeControl.MasterVolume = i;
        }

        private void button3_Click(object sender, EventArgs e)
        {
            volumeControl.IsMute = true;
        }
    }
}
